package com.woniuxy.productServer.controller;


import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.util.Result;
import com.woniuxy.productServer.dto.MovieInfoDto;
import com.woniuxy.productServer.form.movie.MovieAddForm;
import com.woniuxy.productServer.form.movie.MovieChangeForm;
import com.woniuxy.productServer.form.movie.MovieLoadForm;
import com.woniuxy.productServer.param.movie.MovieAddParam;
import com.woniuxy.productServer.param.movie.MovieChangeParam;
import com.woniuxy.productServer.param.movie.MovieLoadParam;
import com.woniuxy.productServer.service.MovieInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.elasticsearch.annotations.MultiField;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import static com.woniuxy.commons.util.Result.getResult;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年03月20日
 */
@RestController
@RequestMapping("/movieInfo")
@Api(tags = "电影")
public class MovieInfoController {
    @Autowired
    private MovieInfoService movieInfoService;

    @PostMapping("/add.api")
    @ApiOperation("新增电影")
    public Result<MovieInfoDto> add(@RequestBody  MovieAddForm form) throws Exception {

        MovieAddParam param = BeanUtil.toBean(form, MovieAddParam.class);
        MovieInfoDto movieInfoDto = movieInfoService.add(param);
        return Result.getResult(MovieInfoDto.class).setMsg("新增电影成功").setData(movieInfoDto);
    }

    @PostMapping("/change.api")
    @ApiOperation("修改电影")
    public Result<Integer> exchange(@RequestBody MovieChangeForm form) throws Exception {

        MovieChangeParam param = BeanUtil.toBean(form, MovieChangeParam.class);
        movieInfoService.change(param);
        return Result.getResult(Integer.class).setMsg("修改电影成功").setData(form.getMovieState());
    }

    @PostMapping("/load")
    @ApiOperation("查询电影")
    public Result<PageInfo<MovieInfoDto>> load(@RequestBody MovieLoadForm form) throws Exception {

        MovieLoadParam param = BeanUtil.toBean(form, MovieLoadParam.class);
        PageInfo<MovieInfoDto> pageInfo= movieInfoService.load(param);
        return Result.getPageInfoResult(MovieInfoDto.class).setMsg("查询电影成功").setData(pageInfo);
    }
}

